package com.brillilab.service.core.experiments.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.experiments.ExperimentGroupRelationMapper;
import com.brillilab.domain.po.experiments.ExperimentGroupRelation;
import com.brillilab.service.core.experiments.IExperimentGroupRelationService;

/**
 * <p>
 * 实验分组 服务实现类
 * </p>
 *
 * @author WuMenghao
 * @since 2019-09-05
 */
@Service
@Transactional
public class ExperimentGroupRelationServiceImpl implements IExperimentGroupRelationService {
    @Resource
    private ExperimentGroupRelationMapper experimentGroupRelationMapper;

    @Override
    public boolean insertBatch(List<ExperimentGroupRelation> entitys) {
        int count = experimentGroupRelationMapper.insertBatch(entitys);
        return count == entitys.size();
    }

    @Override
    public List<ExperimentGroupRelation> selectList(Long experimentId) {
        return experimentGroupRelationMapper.selectList(
                new LambdaQueryWrapper<ExperimentGroupRelation>()
                .eq(ExperimentGroupRelation::getExperimentId, experimentId));
    }

    @Override
    public ExperimentGroupRelation selectById(Long id) {
        return experimentGroupRelationMapper.selectById(id);
    }

    @Override
    public List<ExperimentGroupRelation> selectByParentId(List<Long> parentIds) {
        return experimentGroupRelationMapper.selectList(
                new LambdaQueryWrapper<ExperimentGroupRelation>()
                        .in(ExperimentGroupRelation::getParentId, parentIds));
    }

    @Override
    public boolean deleteBatch(List<Long> ids) {
        return experimentGroupRelationMapper.deleteBatchIds(ids) == ids.size();
    }

    @Override
    public boolean deleteByExperimentId(Long experimentId) {
        return experimentGroupRelationMapper.delete(
                new LambdaQueryWrapper<ExperimentGroupRelation>()
                        .in(ExperimentGroupRelation::getExperimentId, experimentId)) > 0;
    }

	@Override
	public ExperimentGroupRelation insert(ExperimentGroupRelation relation) {
		experimentGroupRelationMapper.insert(relation);
		return relation;
	}
}
